#!/bin/sh
if [ -n "`which include.sh`" ]; then echo "including `which include.sh`";. `which include.sh`; fi
if [ -z "`which include.sh`" ]; then echo "including `which functions.sh`";. `which functions.sh`; fi
local_path=`dirname ${0}`
##########
username=""
password=""
app_url="http://smartphone/repositories/AppsOfMtk/trunk/packages-w1140"
thirdparty_url="http://smartphone/repositories/ThirdParty/Apks"
project_name=""
hardware=""
modem_dir="mediatek/custom/common/modem"
#TARGET_PRODUCT=`ls build/target/product/*.mk | grep "bbk" | xargs basename | awk -F "." '{print $1}'`
product_name=`ls mediatek/config/ | grep "bbk" | xargs basename | awk -F "." '{print $1}'`
work_copy="`pwd`"
echo "$work_copy"

function ShowHelp()
{
	echo "update.sh --app-url AppUrl  -p 项目名 -h hardware --work_copy  work_copy"
}


while test $# != 0
do
    case $1 in
	--username)
	    shift
	    username=$1
	    ;; 
	--password)
	    shift
	    password=$1
	    ;;  
        --app-url)
	    shift
	    app_url=$1
	    ;; 
        --work_copy)
	    shift
	    work_copy=$1
	    ;; 
        --temp-app)
	    shift
	    temp_app_project_name=$1
	    ;; 
	-p)
	    shift
	    project_name=$1
	    ;;
   	-h)
	    shift
	    hardware=$1
	    ;;
	--help|-help)
	    ShowHelp
	    exit
	    ;;
        *)
	    expansion_options=$1
	   ;;
       esac
       shift
done


#svn_options="--username $username --password $password --non-interactive"
###########
#echo "" > ./packageCheckout.sh
ac_url=`sh_get_svn_url \`pwd\` "$svn_options"`
allFD=`svn.shc list $ac_url |sed 's#out/##g' |sed 's#packages/##g'`
result=`question "是否更新整个framework源代码？" 1 no`
if [  "$result" = "yes" ] ; then
  	rm -vrf vendor/bbk/common/3Party

  	for f in $allFD
  	do
    		echo "svn up $f"
    		svn.shc up $f  # $svn_options  #--no-auth-cache
  	done
	
	 framework_version=`sh_get_svn_committed_no_from_url $ac_url "$svn_options"`
        echo "$framework_version" > .version
#       echo 'sed -i "/current_framework_version/s/.*/current_framework_version:${framework_version}/g" $work_copy/svn_version'
        sed -i "/current_framework_version/s/.*/current_framework_version:${framework_version}/g" $work_copy/svn_version

fi



result=`question "是否更新应用代码？" 1 no`
if [  "$result" = "yes" ] ; then
	if [ "$temp_app_project_name" = "" ];then
  	svn-update.sh --url  $app_url  packages/ -p $project_name 
	else
	svn-update.sh --url  $app_url  packages/ -p $temp_app_project_name
	fi
fi

result=`question "是否更新第三方apk？" 1 no`
if [  "$result" = "yes" ] ; then
  	sh_svn_up_thirdparty -p $project_name  -d $product_name --url  $thirdparty_url
fi


framversion=`cat .version`
appversion=`cat packages/.version`
framework_url=`svn info |grep URL |awk '{print $2}'`
echo "$framework_url $framversion" >> ./packageCheckout.sh


